<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no"/>
    <meta name="format-detection" content="email=no"/>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"
          name="viewport">
    <title>注册</title>
    <link rel="stylesheet" type="text/css" href="/stylesheets/loginOrregis.css"/>

</head>
<body ng-app="myApp">
<div class="container"  ng-controller="registerCtrl">
    <div id="registerDiv">
        <div class="panel-heading re">注册</div>
        <form ng-submit="registerSubmit()" novalidate name="userForm">
            <div class="registerInfo">
                <label for="username">用户名:</label>
                <input id="username" name="username" ng-model="userdata.username" required>
                <span class="err" ng-show="userForm.username.$error.required && userForm.username.$touched">用户名不能为空</span>

                <label for="password">密码:</label>
                <input id="password" name="password" type="password" ng-model="userdata.password" required>
                <span class="err" ng-show="userForm.password.$error.required && userForm.password.$touched">密码不能为空</span>

                <label for="confirm_password">确认密码:</label>
                <input id="confirm_password" name="confirm_password" type="password" ng-model="userdata.confirm_password" compare="userdata.password" required>
                <span class="err" ng-show="userForm.confirm_password.$error.compare && userForm.username.$touched">确认密码与密码不一致</span>
            </div>
            <div class="registerSubmitDIv">
                <div class="error">{{message}}</div>
                <button id="registerSubmit" type="submit">注册</button>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript" src="/javascripts/angular.min.js"></script>
<script type="text/javascript" src="/javascripts/myApp.js"></script>
<script type="text/javascript" src="/javascripts/login_register.js"></script>
<script>




    /* function validate1() {
     var username = $("#username").val();
     var password = $("#password").val();
     var confirm_password = $("#confirm_password").val();
     if (username == null || $.trim(username) == "") {
     $("#username").next('.errorInfo').remove();
     $("#username").after('<span class="errorInfo">用户名不能为空</span>');
     return false;
     } else {
     $("#username").next('.errorInfo').remove();
     }
     return true;
     }
     function validate2() {
     var username = $("#username").val();
     var password = $("#password").val();
     var confirm_password = $("#confirm_password").val();
     if (password == null || $.trim(password) == "") {
     $("#password").next('.errorInfo').remove();
     $("#password").after('<span class="errorInfo">密码不能为空</span>');
     return false;
     } else {
     $("#password").next('.errorInfo').remove();
     }
     if (confirm_password != password) {
     $("#confirm_password").next('.errorInfo').remove();
     $("#confirm_password").after('<span class="errorInfo">密码与确认密码不一致</span>');
     return false;
     } else {
     $("#confirm_password").next('.errorInfo').remove();
     }
     return true;
     }
     function validate() {
     if (validate1() && validate2())
     return true;
     }
     function register() {
     var username = $("#username").val();
     var password = $("#password").val();
     var obj = {
     username: username,
     password: password
     };
     if (validate()) {
     $.ajax({
     data: obj,
     url: '/register',
     type: "post",
     dataType: 'json',
     success: function (data) {
     if(data.data=="no"){
     alert("该用户名已被注册");
     }else{
     window.location.assign('/login');
     }
     },
     error: function (data) {
     alert(data);
     }
     });
     }

     }
     $(document).ready(function () {

     $("#registerSubmit").click(function () {
     register();
     });
     $("#username,#password,#confirm_password").keydown(function (e) {
     e = e || event;
     if (e.keyCode === 13) {
     register();
     }
     });

     });
     */
</script>
</body>
</html>

